#include <iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<stdio.h>
using namespace std;
//const int size1 = 10 * 10 * 10 * 10 + 1;
//int A[size1];
bool f(int** A, int& n, int& m)
{
	for (int i = 0; i < n; i++)
	{

		for (int j = 0; j < m; j++)
		{
			if (A[i][j] != 0) { return 1; }
		}
		

	}
	return 0;
}
void back(int** A, int i, int j,int &n,int&m)
{
	if (i >= 0 && i < n && j >= 0 && j < m)
	{
		int t = A[i][j];
		A[i][j] = 0;
		if (j - 1 > -1 && t == A[i][j - 1])
		{
			back(A, i, j-1, n, m);
		}
		if (j + 1 <m && t == A[i][j + 1])
		{
			back(A, i, j + 1, n, m);
		}
		if (i - 1 > -1 && t == A[i-1][j])
		{
			back(A, i-1, j , n, m);
		}
		if (i+ 1 <n && t == A[i+1][j ])
		{
			back(A, i + 1, j, n, m);
		}
		
		
	}
}
int main()
{
	int n,m,x;
	string s;
	cin >> n>>m;
	int** A = new int*[n];

	for (int i = 0; i < n; i++)
	{
		
		A[i] = new int[m];

	}
	for (int i=0;i<n;i++)
	{
		cin >> s;
		for (int j = 0; j < m; j++)
		{
			A[i][j]=s[j];	
		}

		
	}
	//
	/*
	for (int i = 0; i < n; i++)
	{
		
		for (int j = 0; j < m; j++)
		{
			cout<<A[i][j]<<'\t';
		}
		cout << '\n';

	}
	*/
	int re = 0;
	for (int i = 0; i < n; i++)
	{

		for (int j = 0; j < m; j++)
		{
			if (A[i][j] != 0)
			{
				back(A, i, j, n, m);
				re++;
			}
		}
		

	}
	cout << re;
	return 0;
}
